package cn.sxt.clinic.controller;

import cn.sxt.clinic.pojo.Doctor;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/admin")
@Controller
public class LoginController {


    @RequestMapping("/loginPage")
    public String index(){
        return "loginManager";
    }
    @RequestMapping("/loginErr")
    public String indexErr(HttpServletRequest request, Model m){

        String shiroLoginFailure = (String) request.getAttribute("shiroLoginFailure");

        if (StringUtils.isNotBlank(shiroLoginFailure)){
            if (UnknownAccountException.class.getName().equals(shiroLoginFailure)){
                m.addAttribute("errMsg","账号错误");
            }else if (IncorrectCredentialsException.class.getName().equals(shiroLoginFailure)){
                m.addAttribute("errMsg","密码错误");
            }

        }

        return "loginManager";
    }
}
